//
//  VlionActionSheet.m
//  TestActionSheet
//
//  Created by Cui Lionel on 10-12-8.
//  Copyright 2010 vlion. All rights reserved.
//

#import "UEXActionSheet.h"
#import "AppUtility.h"

@implementation UEXActionSheet
@synthesize view;
@synthesize toolBar;
@synthesize uexDelegate;

-(id)initWithHeight:(float)height WithSheetTitle:(NSString*)title
{//height = 84, 134, 184, 234, 284, 334, 384, 434, 484
	self = [super init];
    if (self) 
	{
		int theight = height - 40;
		int btnnum = theight/50;
		for(int i=0; i<btnnum; i++)
		{
			[self addButtonWithTitle:@" "];
		}
		toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
		toolBar.barStyle = UIBarStyleDefault;
		float sysVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
		UIImage *bgImg = [AppUtility getLocalImageWithCache:@"nav_bg"];
		if (sysVersion >= 5.0) {
			[toolBar setBackgroundImage:bgImg forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
		}
		UIBarButtonItem *leftButton = [AppUtility getToolBtnItemLeftWith:@selector(docancel) andTitle:@"取消" andTarget:self];
		leftButton.style = UIBarButtonItemStylePlain;
		UIBarButtonItem *titleButton = [[UIBarButtonItem alloc] initWithTitle:title style: UIBarButtonItemStylePlain target: nil action: nil];
		UIBarButtonItem *rightButton = [AppUtility getToolBtnItemRightWith:@selector(done) andTitle:@"确认" andTarget:self];
		rightButton.style = UIBarButtonItemStyleDone;
		UIBarButtonItem *fixedButton  = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target: nil action: nil];
		NSArray *array = [[NSArray alloc] initWithObjects: leftButton,fixedButton, titleButton,fixedButton, rightButton, nil];
		[toolBar setItems: array];		
		[titleButton release];
		[fixedButton release];
		[array       release];
		[self addSubview:toolBar];
		view = [[UIView alloc] initWithFrame:CGRectMake(0, 44, 320, height-44)];
		view.backgroundColor = [UIColor groupTableViewBackgroundColor];
		[self addSubview:view];
    }
    return self;
}

- (void)done {
	[self dismissWithClickedButtonIndex:0 animated:YES];
	if (self.uexDelegate!=nil && [(NSObject*)self.uexDelegate respondsToSelector:@selector(didDoneBtnClicked)]) {
		[self.uexDelegate didDoneBtnClicked];
	}
}

- (void)docancel {
	[self dismissWithClickedButtonIndex:0 animated:YES];
	if (self.uexDelegate!=nil && [(NSObject*)self.uexDelegate respondsToSelector:@selector(didCancelBtnClicked)]) {
		[self.uexDelegate didCancelBtnClicked];
	}
}

- (void)dealloc {
	[view release];
	[toolBar release];
	[super dealloc];
}
@end
